unit gmStreetView;

interface

{$INCLUDE gmConfig.inc}

uses
  SysUtils, {$IFDEF DELPHI6_UP}Variants,{$ENDIF} BrowserTools, JScriptObjects,
  gmBase, gmMVC;

const
  StreetViewPanoramaMethod_GetEnableCloseButton = 'getEnableCloseButton';
  StreetViewPanoramaMethod_GetLinks             = 'getLinks';
  StreetViewPanoramaMethod_GetPano              = 'getPano';
  StreetViewPanoramaMethod_GetPosition          = 'getPosition';
  StreetViewPanoramaMethod_GetPov               = 'getPov';
  StreetViewPanoramaMethod_GetVisible           = 'getVisible';
  StreetViewPanoramaMethod_N                    = 'N';
  StreetViewPanoramaMethod_SetEnableCloseButton = 'setEnableCloseButton';
  StreetViewPanoramaMethod_SetPosition          = 'setPosition';
  StreetViewPanoramaMethod_SetPano              = 'setPano';
  StreetViewPanoramaMethod_SetPov               = 'setPov';
  StreetViewPanoramaMethod_SetVisible           = 'setVisible';
  StreetViewPanoramaMethod_VisibleChanged       = 'visible_changed';

  StreetViewPovProp_Heading                     = 'heading';
  StreetViewPovProp_Pitch                       = 'pitch';
  StreetViewPovProp_Zoom                        = 'zoom';

  StreetViewStatusProp_Ok                       = 'OK';
  StreetViewStatusProp_UnknownError             = 'UNKNOWN_ERROR';
  StreetViewStatusProp_ZeroResults              = 'ZERO_RESULTS';

type
  TStreetViewPov = class;

  TStreetViewPanorama = class(TMVCObject)
  private
    FLatLng: TLatLng;
    FLinks: TJScriptArray;
    FPosition: TLatLng;
    FPov: TStreetViewPov;
  protected
    procedure Visible_changed;
    function N: OleVariant;
  public
    destructor Destroy; override;
    class function IsObjectFromDisp(Disp: IDispatch): Boolean; override;
//    procedure RegisterPanoProvider(c: OleVariant);
    procedure SetEnableCloseButton(Flag: Boolean);
    procedure SetPano(Pano: String);
    procedure SetPosition(LatLng: TLatLng);
    procedure SetPov(Pov: TStreetViewPov);
    procedure SetVisible(Flag: Boolean);
    function GetEnableCloseButton: Boolean;
    function GetLinks: TJScriptArray;
    function GetPano: String;
    function GetPosition: TLatLng;
    function GetPov: TStreetViewPov;
    function GetVisible: Boolean;
  end;

  TStreetViewPanoramaOptions = class(TJScriptObject)
  public
    class function IsObjectFromDisp(Disp: IDispatch): Boolean; override;
  end;

  TStreetViewPov = class(TJScriptObject)
  private
    procedure SetHeading(Value: Double);
    procedure SetPitch(Value: Double);
    procedure SetZoom(Value: Double);
    function GetHeading: Double;
    function GetPitch: Double;
    function GetZoom: Double;
  protected
  public
    class function IsObjectFromDisp(Disp: IDispatch): Boolean; override;
    property Heading: Double read GetHeading write SetHeading;
    property Pitch: Double read GetPitch write SetPitch;
    property Zoom: Double read GetZoom write SetZoom;
  end;

  TStreetViewStatus = class(TJScriptObject)
  private
    procedure SetOk(Value: String);
    procedure SetUnknown_Error(Value: String);
    procedure SetZero_Results(Value: String);
    function GetOk: String;
    function GetUnknown_Error: String;
    function GetZero_Results: String;
  protected
  public
    class function IsObjectFromDisp(Disp: IDispatch): Boolean; override;
    property Ok: String read GetOk write SetOk;
    property Unknown_Error: String read GetUnknown_Error write SetUnknown_Error;
    property Zero_Results: String read GetZero_Results write SetZero_Results;
  end;

function CreateStreetViewPanoramaWrapper(Script: TCustomScript; Dispatch: IDispatch): TStreetViewPanorama;
function CreateStreetViewStatusWrapper(Script: TCustomScript; Dispatch: IDispatch): TStreetViewStatus;

implementation

uses
  gmAPI;

function CreateStreetViewPanoramaWrapper(Script: TCustomScript; Dispatch: IDispatch): TStreetViewPanorama;
begin
  Result:=TStreetViewPanorama.Create(Script,Dispatch);
end;

function CreateStreetViewStatusWrapper(Script: TCustomScript; Dispatch: IDispatch): TStreetViewStatus;
begin
  Result:=TStreetViewStatus.Create(Script,Dispatch);
end;

//------------------------------------------------------------------------------
//TStreetViewPanorama

destructor TStreetViewPanorama.Destroy;
begin
  FLatLng.Free;
  FLinks.Free;
  FPosition.Free;
  FPov.Free;
  inherited;
end;

class function TStreetViewPanorama.IsObjectFromDisp(Disp: IDispatch): Boolean;
begin
  Result:=(GetJSObjectType(Disp)=otObject) and
          ObjectHasMembers(Disp,[StreetViewPanoramaMethod_GetEnableCloseButton,
                                 StreetViewPanoramaMethod_SetEnableCloseButton,
                                 StreetViewPanoramaMethod_GetPano]);
end;

//procedure TStreetViewPanorama.RegisterPanoProvider(c: OleVariant);
//begin
//end;

function TStreetViewPanorama.GetEnableCloseButton: Boolean;
begin
  Result:=VarAsBoolean(Exec(StreetViewPanoramaMethod_GetEnableCloseButton));
end;

procedure TStreetViewPanorama.SetEnableCloseButton(Flag: Boolean);
begin
  Exec(StreetViewPanoramaMethod_SetEnableCloseButton,[Flag]);
end;

function TStreetViewPanorama.GetPano: String;
begin
  Result:=VarAsString(Exec(StreetViewPanoramaMethod_GetPano));
end;

procedure TStreetViewPanorama.SetPano(Pano: String);
begin
  Exec(StreetViewPanoramaMethod_SetPano,[Pano]);
end;

function TStreetViewPanorama.GetPosition: TLatLng;
var
  Position: OleVariant;
begin
  Result:=nil;
  Position:=Exec(StreetViewPanoramaMethod_GetPosition);
  if VarIsValidDispatch(Position) then
  begin
    if assigned(FPosition)
      then FPosition.Disp:=Position
      else FPosition:=CreateLatLngWrapper(Script,Position);
    Result:=FPosition;
  end;
end;

procedure TStreetViewPanorama.SetPosition(LatLng: TLatLng);
begin
  Exec(StreetViewPanoramaMethod_SetPosition,LatLng);
end;

function TStreetViewPanorama.GetPov: TStreetViewPov;
var
  Pov: OleVariant;
begin
  Result:=nil;
  Pov:=Exec(StreetViewPanoramaMethod_GetPov);
  if VarIsValidDispatch(Pov) then
  begin
    if assigned(FPov)
      then FPov.Disp:=Pov
      else FPov:=TStreetViewPov.Create(Script,Pov);
    Result:=FPov;
  end;
end;

procedure TStreetViewPanorama.SetPov(Pov: TStreetViewPov);
begin
  Exec(StreetViewPanoramaMethod_SetPov,Pov);
end;

function TStreetViewPanorama.GetVisible: Boolean;
begin
  Result:=VarAsBoolean(Exec(StreetViewPanoramaMethod_GetVisible));
end;

procedure TStreetViewPanorama.SetVisible(Flag: Boolean);
begin
  Exec(StreetViewPanoramaMethod_SetVisible,[Flag]);
end;

function TStreetViewPanorama.GetLinks: TJScriptArray;
var
  Links: OleVariant;
begin
  Result:=nil;
  Links:=Exec(StreetViewPanoramaMethod_GetLinks);
  if VarIsValidDispatch(Links) then
  begin
    if assigned(FLinks)
      then FLinks.Disp:=Links
      else FLinks:=CreateJScriptArrayWrapper(Script,Links);
    Result:=FLinks;
  end;
end;

function TStreetViewPanorama.N: OleVariant;
begin
  Result:=Exec(StreetViewPanoramaMethod_N);
end;

procedure TStreetViewPanorama.Visible_changed;
begin
  Exec(StreetViewPanoramaMethod_VisibleChanged);
end;

//------------------------------------------------------------------------------
//TStreetViewPanoramaOptions

class function TStreetViewPanoramaOptions.IsObjectFromDisp(Disp: IDispatch): Boolean;
begin
  Result:=false; //(GetJSObjectType(Disp)=otObject) and ObjectHasMembers(Disp,[,,]);
end;

//------------------------------------------------------------------------------
//TStreetViewPov

class function TStreetViewPov.IsObjectFromDisp(Disp: IDispatch): Boolean;
begin
  Result:=(GetJSObjectType(Disp)=otObject) and
          ObjectHasMembers(Disp,[StreetViewPovProp_Heading,
                                 StreetViewPovProp_Pitch,
                                 StreetViewPovProp_Zoom]);
end;

function TStreetViewPov.GetHeading: Double;
begin
  Result:=GetPropAsDouble(StreetViewPovProp_Heading);
end;

procedure TStreetViewPov.SetHeading(Value: Double);
begin
  SetProp(StreetViewPovProp_Heading,Value,true);
end;

function TStreetViewPov.GetPitch: Double;
begin
  Result:=GetPropAsDouble(StreetViewPovProp_Pitch);
end;

procedure TStreetViewPov.SetPitch(Value: Double);
begin
  SetProp(StreetViewPovProp_Pitch,Value,true);
end;

function TStreetViewPov.GetZoom: Double;
begin
  Result:=GetPropAsDouble(StreetViewPovProp_Zoom);
end;

procedure TStreetViewPov.SetZoom(Value: Double);
begin
  SetProp(StreetViewPovProp_Zoom,Value,true);
end;

//------------------------------------------------------------------------------
//TStreetViewStatus

class function TStreetViewStatus.IsObjectFromDisp(Disp: IDispatch): Boolean;
begin
  Result:=(GetJSObjectType(Disp)=otObject) and
          ObjectHasMembers(Disp,[StreetViewStatusProp_Ok,
                                 StreetViewStatusProp_UnknownError,
                                 StreetViewStatusProp_ZeroResults]);
end;

function TStreetViewStatus.GetOk: String;
begin
  Result:=GetPropAsString(StreetViewStatusProp_Ok);
end;

procedure TStreetViewStatus.SetOk(Value: String);
begin
  SetProp(StreetViewStatusProp_Ok,Value);
end;

function TStreetViewStatus.GetUnknown_Error: String;
begin
  Result:=GetPropAsString(StreetViewStatusProp_UnknownError);
end;

procedure TStreetViewStatus.SetUnknown_Error(Value: String);
begin
  SetProp(StreetViewStatusProp_UnknownError,Value);
end;

function TStreetViewStatus.GetZero_Results: String;
begin
  Result:=GetPropAsString(StreetViewStatusProp_ZeroResults);
end;

procedure TStreetViewStatus.SetZero_Results(Value: String);
begin
  SetProp(StreetViewStatusProp_ZeroResults,Value);
end;

end.
